package gui.dialogs;

import game.GameField;
import gui.components.Dialogable;

import java.awt.Container;
import java.awt.Window;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.List;

import javax.swing.JDialog;

import utility.WindowManipulator;

public abstract class GameDialog extends JDialog{
	public final static int BUY = 1;
	public final static int BUY_HOUSES = 2;
	private static boolean lastBoolOption;
	
	private Window parent;
	private GameDialog INSTANCE;
	
	public static boolean getDialog(Window parent, GameField field, int dialogType){
		GameDialog dialog;
		if(dialogType==BUY){
			parent.setEnabled(false);
			dialog = new BuyDialog(parent,field);			
		}
		
		return lastBoolOption;
	}
	
	public static void getListDialog(Window parent, List<Dialogable> list, ActionListener al,int dialogType){
		GameDialog dialog;
		if(dialogType==BUY_HOUSES){
			parent.setEnabled(false);
			dialog = new ListDialog(parent, list, "BUY HOUSES", "Buy", al);			
		}
	}
	
	public static void getHelpDialog(Window parent){
		GameDialog dialog;
			parent.setEnabled(false);
			dialog = new HelpDialog(parent);			
	}
	
	protected static void setLastBoolOption(boolean bool){
		lastBoolOption = bool;
	}
	
	public GameDialog(Window parent){
			super();
			INSTANCE = this;
			this.parent = parent;
			Container c = this.getContentPane();
			
			c.setLayout(null);			
			
			this.setUndecorated(true);
			this.setResizable(false);
			this.setModal(true);
			this.addMouseMotionListener(new MouseMotionListener() {
				
				@Override
				public void mouseMoved(MouseEvent m) {
					// TODO Auto-generated method stub
				
					
				}
				
				@Override
				public void mouseDragged(MouseEvent m) {
					/*int newX1 =  m.getXOnScreen();
					int newX2 = m.getX();
					int newx = newX1 + newX2;
					int newy = newX1-newX2;
					
					System.out.println(newX2+","+newX1+"="+(newx));
					
					int newY = m.getYOnScreen();
					INSTANCE.setLocation(newx,newY);*/					
				}
			});
		
	}
	
	protected GameDialog getInstance(){
		return INSTANCE;
	}
	
	protected Window getParentWindow(){
		return parent;
	}
}
